//
//  ListTapAlertView.m
//  LeaveLight
//
//  Created by pro1 on 2019/3/8.
//  Copyright © 2019 xsl. All rights reserved.
//

#import "ListTapAlertView.h"

@interface ListTapAlertView ()



@end

@implementation ListTapAlertView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        //三角形
        UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height - 5) cornerRadius:5.0];
        UIBezierPath *trianglePath = [[UIBezierPath alloc]init];
        [trianglePath moveToPoint:CGPointMake(self.frame.size.width/2- 12,self.frame.size.height-5)];;
        [trianglePath addLineToPoint:CGPointMake(self.frame.size.width/2 - 10,self.frame.size.height)];
        [trianglePath addLineToPoint:CGPointMake(self.frame.size.width/2 - 10 + 2,self.frame.size.height-5)];
        //扩展绘制路径
        [path appendPath:trianglePath];
        CAShapeLayer *fillLayer = [CAShapeLayer layer];
        fillLayer.path= path.CGPath;
        fillLayer.fillColor= [UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.5].CGColor;
        [self.layer insertSublayer:fillLayer atIndex:0];
        
        UIView *line = [[UIView alloc] initWithFrame:CGRectMake(self.frame.size.width/2 - 0.5, 0, 1.0, self.frame.size.height - 5)];
        line.backgroundColor = [UIColor whiteColor];
        [self addSubview:line];
        
        UIButton *copyBtn = [self creatBtnWith:@"复制" tag:100];
        UIButton *shareBtn = [self creatBtnWith:@"分享" tag:101];
        [self addSubview:copyBtn];
        [self addSubview:shareBtn];
    }
    return self;
}

- (UIButton *)creatBtnWith:(NSString *)title tag:(NSInteger)tag{
    CGFloat width = (self.frame.size.width - 1)/2;
    UIButton *button = [[UIButton alloc] init];
    [button setTitle:title forState:UIControlStateNormal];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize:14];
    button.tag = tag;
    button.frame = CGRectMake(width * (tag - 100), 0, width, self.frame.size.height - 5);
    [button addTarget:self action:@selector(listTapAlertButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
    return button;
}

- (void)listTapAlertButtonPressed:(UIButton *)sender{
    [self removeFromSuperview];
    if (self.tapBtnPressedBlock) {
        self.tapBtnPressedBlock(sender.tag - 100);
    }
}

@end
